var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/Attachment/views/formAttachment/index.tsx
var formAttachment_exports = {};
__export(formAttachment_exports, {
  FormAttachment: () => FormAttachment
});
module.exports = __toCommonJS(formAttachment_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_util = require("../../../../util");
var import_AttachmentContext = require("../../AttachmentContext");
var import_components = require("../../components");
var import_components2 = require("./components");
var import_index = require("./index.less");
var OriginFormAttachment = (props) => {
  const [modal, contextHolder] = import_antd.Modal.useModal();
  const attachmentContextValues = (0, import_AttachmentContext.useAttachment)();
  const {
    beforeUploadValidate,
    accept,
    maxCount,
    disabled,
    actions,
    permission,
    attachmentRecordList,
    loading,
    isReady,
    uploading,
    onUploadStateChange,
    attachmentFileList,
    onContentChanged
  } = attachmentContextValues;
  const {
    style = {},
    thumbEnabled = false,
    uploadRef = (0, import_react.useRef)(null),
    tableStyle = {},
    labelConfig,
    simpleUpload = false
  } = props;
  const commonProps = {
    accept,
    maxCount,
    uploadRef,
    onUploaded: onContentChanged,
    onBeforeUpload: beforeUploadValidate,
    onUploadStateChange
  };
  const [curRow, setCurRow] = (0, import_react.useState)();
  const content = thumbEnabled ? /* @__PURE__ */ React.createElement(
    import_components2.ImageUpload,
    {
      ...commonProps,
      attachmentFileList,
      disabled: !isReady || disabled || (permission == null ? void 0 : permission.add) === 0 || uploading,
      onRemove: (file) => {
        const params = [file];
        actions.delete(params);
      }
    }
  ) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
    import_components2.AttachmentToolbar,
    {
      ...commonProps,
      disabled,
      permission,
      isReady,
      simpleUpload,
      uploading,
      count: attachmentRecordList.length || 0,
      zipDownload: actions.zipDownload,
      openAttachment: () => actions.openTableAttachment({ labelConfig, modal })
    }
  ), attachmentFileList.length > 0 && /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { style: { paddingTop: 12 } }, /* @__PURE__ */ React.createElement(
    import_antd.List,
    {
      size: "small",
      style: {
        ...tableStyle,
        maxHeight: 250,
        overflow: "auto"
      },
      dataSource: attachmentFileList,
      loading,
      itemLayout: "horizontal",
      renderItem: (row) => {
        const uploaded = row.status === "done" || row.status === void 0;
        const listItemActions = [
          /* @__PURE__ */ React.createElement(
            "a",
            {
              style: {
                color: "var(--primary-color)",
                visibility: uploaded ? "unset" : "hidden"
              },
              onClick: () => {
                if (!uploaded)
                  return;
                setCurRow(row);
              }
            },
            "备注"
          )
        ];
        const isPreview = uploaded && actions.isPreview(row.asrName || row.fileName);
        const isFail = row.status === "fail";
        return /* @__PURE__ */ React.createElement(import_antd.List.Item, { style: { padding: "8px 4px" }, actions: listItemActions }, /* @__PURE__ */ React.createElement("div", { className: `attachment-flex-center ${isFail ? "upload-failed" : ""}` }, /* @__PURE__ */ React.createElement(
          import_components.FileView,
          {
            data: {
              fileName: row.asrName || row.fileName,
              fileSize: row.originFileSize || row.fileSize,
              status: row.status,
              percent: row.percent
            },
            isPreview,
            handlePreview: () => row.asrFid && actions.preview(row.asrFid)
          }
        ), /* @__PURE__ */ React.createElement(import_antd.Space, { size: 0, className: "attachment-space-btn" }, uploaded && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
          import_components.AttachmentButton,
          {
            size: "small",
            type: "link",
            permissionStatus: permission == null ? void 0 : permission.preview,
            disabled: !isPreview,
            onClick: () => row.asrFid && actions.preview(row.asrFid)
          },
          "预览"
        ), /* @__PURE__ */ React.createElement(
          import_components.AttachmentButton,
          {
            size: "small",
            type: "link",
            permissionStatus: permission == null ? void 0 : permission.download,
            onClick: () => actions.download(row)
          },
          "下载"
        )), /* @__PURE__ */ React.createElement(
          import_components.AttachmentButton,
          {
            size: "small",
            type: "link",
            disabled,
            permissionStatus: permission == null ? void 0 : permission.delete,
            onClick: () => actions.delete([row])
          },
          "删除"
        ))), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { style: { width: 150 } }, row.asrFilldt), /* @__PURE__ */ React.createElement("div", { style: { width: 70 } }, row.userName), !import_util.iup.isNullOrEmpty(labelConfig) && /* @__PURE__ */ React.createElement(
          import_components.LabelSelect,
          {
            labelConfig: {
              ...labelConfig,
              value: row.label,
              disabled: disabled || !uploaded
            },
            fileId: row.asrFid,
            onChangeCallback: onContentChanged
          }
        )));
      }
    }
  )));
  return /* @__PURE__ */ React.createElement(import_util.Layout, { className: "iup-form-attachment", style, direction: "row" }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { className: "iup-form-attachment-content" }, content, contextHolder), /* @__PURE__ */ React.createElement(
    import_components.RemarkModal,
    {
      data: curRow || {},
      visible: curRow !== void 0,
      disabled,
      onCancel: () => setCurRow(void 0),
      onSaved: onContentChanged
    }
  ));
};
var FormAttachment = (0, import_react.forwardRef)(
  ({
    style,
    thumbEnabled,
    uploadRef,
    tableStyle,
    simpleUpload,
    labelConfig,
    ...rest
  }, ref) => {
    return /* @__PURE__ */ React.createElement(import_AttachmentContext.AttachmentProvider, { ...rest, ref }, /* @__PURE__ */ React.createElement(
      OriginFormAttachment,
      {
        style,
        thumbEnabled,
        uploadRef,
        tableStyle,
        simpleUpload,
        labelConfig
      }
    ));
  }
);
(0, import_util.registerComponent)({ Attachment: FormAttachment });
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FormAttachment
});
